<?php
//前台相关
$api = app('Dingo\Api\Routing\Router');
$array = [
    'middleware' => [
        'api.throttle',
//        'serializer:array',
        'bindings'
    ],
    'limit' => 60,
    'expires' => 1
];
$api->version('v1', $array, function ($api) {
    $api->group(['prefix'=>'article'],function ($api) {
        $api->get('index', [\App\Http\Controllers\Web\WriteController::class, 'index'])->name('index');
        $api->resource('writes', \App\Http\Controllers\Web\WriteController::class,[
            'only'=> ['index','show']
        ]);
        //获得分类
        $api->resource('categories',\App\Http\Controllers\Web\CategoryController::class,['only' => ['index','show']]);
        //个人中心和查看其他人信息
        $api->get('userinfo',[\App\Http\Controllers\Web\UserController::class,'userinfo'])->name('userinfo');
        //发现
        $api->get('find',[\App\Http\Controllers\Web\WriteController::class,'find']);
        //需要登录的路由
        $api->group(['middleware' => ['api.auth','permission']], function ($api) {
            $api->resource('writes', \App\Http\Controllers\Web\WriteController::class,[
                'expect'=> ['destroy']
            ]);
            //代替删除文章   可以建立回收站
            $api->post('/{write}/del',[\App\Http\Controllers\Web\WriteController::class,'lock'])->name('write.lock');

            //收藏文章
            $api->post('/col',[\App\Http\Controllers\Web\WriteController::class,'collect'])->name('write.col');
            //举报发言
            $api->post('/report',[\App\Http\Controllers\Web\CommentController::class,'report'])->name('comment.report');
            //评论
            $api->resource('comments', \App\Http\Controllers\Web\CommentController::class,[
                'only'=> ['store','index']
            ]);
            //删除评论
            $api->put('comments/{comment}/del',[\App\Http\Controllers\Web\CommentController::class,'lock'])->name('commnets.del');
            //反馈意见
            $api->post('/feedback',[\App\Http\Controllers\Web\FeedbackController::class,'back'])->name('user.feedback');
            //更改用户信息
            $api->post('/infochange',[\App\Http\Controllers\Web\UserController::class,'info_change'])->name('user.infochange');
            //改变头像
            $api->post('/avatarchange',[\App\Http\Controllers\Web\UserController::class,'avatar_change'])->name('user.avatarchange');
            //看收藏
            $api->get('collect_show',[\App\Http\Controllers\Web\WriteController::class,'collect_show'])->name('user.col_show');
            //我的文章
            $api->get('mywrites',[\App\Http\Controllers\Web\WriteController::class,'my_writes'])->name('user.mywrites');


        });
    });
});

